package com.shop.controller;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.shop.Utils.PageBean;
import com.shop.Utils.ResponseMessage;
import com.shop.Utils.UUIDUtiils;
import com.shop.po.Adminuser;
import com.shop.po.Category;
import com.shop.po.Categorysecond;
import com.shop.po.Message;
import com.shop.po.Orders;
import com.shop.po.Product;
import com.shop.po.User;
import com.shop.service.CategorySecondService;
import com.shop.service.CategoryService;
import com.shop.service.MessageService;
import com.shop.service.OrderService;
import com.shop.service.ProductService;
import com.shop.service.UserService;

@Controller
public class AdminController {
	@Autowired
	private UserService userService;
	@Autowired
	public CategoryService categoryService;
	@Autowired
	public CategorySecondService categorySecondService;
	@Autowired
	public ProductService productService;
	@Autowired
	private OrderService orderService;
	@Autowired
	private MessageService messageService;

	@RequestMapping("/admin/admin_findAll")
	public String admin_findAll(Model model, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		List<User> userList = userService.admin_findAll();
		model.addAttribute("userList", userList);
		return "admin/user/list";
	}

	// 查询用户
	@RequestMapping("/admin/admin_selectByUsername")
	public String admin_selectByUsername(String username, Model model, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		List<User> user = userService.selectByUname(username);
		request.setAttribute("userList", user);
		return "admin/user/list";
	}

	@RequestMapping("/admin/adminCategory_findAll")
	public String adminCategory_findAll(Model model, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		List<Category> categoryList = categoryService.adminbFindCategory();
		/*
		 * for (Category category : categoryList) {
		 * System.out.println(category.getCname()); }
		 */
		model.addAttribute("categoryList", categoryList);
		return "admin/category/list";
	}

	// admin 的一级分类查询子类
	@RequestMapping("/admin/adminCategory_getzl")
	public String adminCategory_getzl(int cid, Model model, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		List<Categorysecond> categoryzl = categorySecondService.adminCategory_getzl(cid);
		model.addAttribute("categoryList", categoryzl);
		return "admin/categorysecond/a";
	}

	/*
	 * @RequestMapping("/admin/findproductByCategorysecond") public String
	 * findproductByCategorysecond(@RequestParam int page, @RequestParam int csid,
	 * Model model, HttpServletRequest request) throws Exception { PageBean<Product>
	 * ProductPageBean = productService.finbProductByCsid(csid, page);
	 * System.out.println(csid); model.addAttribute("allProPageBean",
	 * ProductPageBean); return "admin/product/list"; }
	 */

	@RequestMapping("/admin/findproByCs")
	public String findproByCs(@RequestParam int csid, Model model, HttpServletRequest request) throws Exception {
		// 查询二级商品种类
		List<Categorysecond> categoryList = categorySecondService.findAll();
		model.addAttribute("categoryList", categoryList);
		// 按照csid查询商品
		List<Product> Productlist = productService.findProByCsid(csid);
		System.out.println(csid);
		model.addAttribute("srList", Productlist);
		return "admin/product/search";
	}

	/*
	 * @RequestMapping("/getcategory_name")
	 * 
	 * @ResponseBody public String getcategory_name(HttpServletRequest request)
	 * throws Exception { List<String> g = new ArrayList<String>(); g =
	 * categoryService.getcategory_name(); ObjectMapper mapper = new ObjectMapper();
	 * String staffsJson = null; try { staffsJson = mapper.writeValueAsString(g);
	 * System.out.println(g); } catch (JsonProcessingException e) {
	 * e.printStackTrace(); } return staffsJson; }
	 */

	@RequestMapping("/admin/adminCategory_add")
	public String adminCategory_add(Model model, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
//		List<Category> categoryList = categoryService.adminbFindCategory();
//		model.addAttribute("categoryList", categoryList);
		return "admin/category/add";
	}

	@RequestMapping("/admin/adminCategory_save")
	public String adminCategory_save(@RequestParam String cname, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		Category addCategory = new Category();
		addCategory.setCname(cname);
		categoryService.addCategory(addCategory);
		return "redirect:/admin/adminCategory_findAll.action";
	}

	@RequestMapping("/admin/adminCategory_edit")
	public String adminCategory_delete(@RequestParam int cid, Model model, HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		Category existCategory = categoryService.findCategory(cid);
		model.addAttribute("existCategory", existCategory);
		return "admin/category/edit";
	}

	@RequestMapping("/admin/adminCategory_update")
	public String adminCategory_update(@RequestParam int cid, @RequestParam String cname, HttpServletRequest request) {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		request.getSession().removeAttribute("error2");
		Category category = new Category();
		category.setCid(cid);
		category.setCname(cname);
		categoryService.adminCategory_update(category);
		return "redirect:/admin/adminCategory_findAll.action";
	}

	@RequestMapping("/admin/adminCategory_delete")
	public String adminCategory_delete(@RequestParam int cid, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
			categoryService.deleteCategoryByCid(cid);
			
		return "redirect:/admin/adminCategory_findAll.action";
	}

	// admin 的二级分类的管理
	@RequestMapping("/admin/adminCategorySecond_findAllByPage")
	public String adminCategorySecond_findAllByPage(@RequestParam int page, Model model, HttpServletRequest request) {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		PageBean<Categorysecond> csPageBean = categorySecondService.adminCategorySecond_findAllByPage(page);
		/*
		 * List<Categorysecond> list = csPageBean.getList(); for (Categorysecond
		 * categorysecond : list) { System.out.println(categorysecond.getCsname()); }
		 */
		model.addAttribute("csPageBean", csPageBean);
		return "admin/categorysecond/list";
	}

	// 二级分类添加
	@RequestMapping("admin/adminCategorySecond_addPage")
	public String adminCategorySecond_addPage(Model model, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		List<Category> categoryList = categoryService.adminbFindCategory();
		model.addAttribute("categoryList", categoryList);
		return "admin/categorysecond/add";
	}

//查询一级下拉种类
	@RequestMapping("admin/adminCategorySecond")
	public String adminCategorySecond(Model model, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		List<Category> categoryList = categoryService.adminbFindCategory();
		model.addAttribute("categoryList", categoryList);
		// return "admin/category/list";
		return "admin/product/list";
	}

	// 二级分类保存
	@RequestMapping("admin/adminCategorySecond_save")
	public String adminCategorySecond_save(@RequestParam String csname, @RequestParam int cid,
			HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		Categorysecond categorysecond = new Categorysecond();
		categorysecond.setCsname(csname);
		categorysecond.setCid(cid);
		categorySecondService.adminCategorySecond_save(categorysecond);
		return "redirect:/admin/adminCategorySecond_findAllByPage.action?page=1";
	}

	// 二级分类编辑
	@RequestMapping("admin/adminCategorySecond_edit")
	public String adminCategorySecond_edit(@RequestParam int csid, Model model, HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		// 查询出所有的一级分类
		List<Category> categoryList = categoryService.adminbFindCategory();
		model.addAttribute("categoryList", categoryList);
		Categorysecond findByCsid = categorySecondService.findByCsid(csid);
		model.addAttribute("findByCsid", findByCsid);
		return "admin/categorysecond/edit";
	}

	/*
	 * @RequestMapping("admin/adminCategorySecond_update") public String
	 * adminCategorySecond_update(@RequestParam String csname, @RequestParam int
	 * csid, HttpServletRequest request) { Adminuser adminuserLogin = (Adminuser)
	 * request.getSession().getAttribute("adminuserLogin"); if (adminuserLogin ==
	 * null) { request.getSession().setAttribute("message", "对不起您还没有登录"); return
	 * "admin/index"; } Categorysecond categorysecond = new Categorysecond();
	 * categorysecond.setCsname(csname); categorysecond.setCsid(csid);
	 * categorySecondService.adminCategorySecond_update(categorysecond); return
	 * "redirect:/admin/adminCategorySecond_findAllByPage.action?page=1"; }
	 */

	@RequestMapping("admin/adminCategorySecond_update")
	public String adminCategorySecond_update(@RequestParam String csname, @RequestParam int cid,
			HttpServletRequest request) {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		Categorysecond categorysecond = new Categorysecond();
		categorysecond.setCsname(csname);
		categorysecond.setCsid(cid);
		categorySecondService.adminCategorySecond_update(categorysecond);
		return "redirect:/admin/adminCategorySecond_findAllByPage.action?page=1";
	}

	@RequestMapping("admin/adminCategorySecond_delete")
	public String adminCategorySecond_delete(@RequestParam int csid, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		List<Product> Productlist = productService.findProByCsid(csid);
		if(Productlist==null) {
			categorySecondService.adminCategorySecond_delete(csid);
			request.getSession().removeAttribute("error");

		}else {
			request.getSession().setAttribute("error","此分类无法删除!");
		}
		return "redirect:/admin/adminCategorySecond_findAllByPage.action?page=1";
	}
	
	

	// admin的商品管理——————————后台商品列表
	@RequestMapping("/admin/adminProduct_findAllByPage")
	public String adminProduct_findAllByPage(@RequestParam int page, Model model, HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		// 查询二级商品种类
		List<Categorysecond> categoryList = categorySecondService.findAll();
		model.addAttribute("categoryList", categoryList);
		// 查询所有商品
		PageBean<Product> allProPageBean = productService.findAllProduct(page);
		model.addAttribute("allProPageBean", allProPageBean);
		System.out.println(allProPageBean);
		return "admin/product/list";
	}

	@RequestMapping("/admin/adminProduct_addPage")
	public String adminProduct_addPage(Model model, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		// 查询出所有的二级分类
		List<Categorysecond> cslist = categorySecondService.findAll();
		/*
		 * for (Categorysecond categorysecond : cslist) {
		 * System.out.println(categorysecond.getCsname()); }
		 */
		model.addAttribute("cslist", cslist);
		return "admin/product/add";
	}

	@RequestMapping("/admin/adminProduct_save")
	public String adminProduct_save(Product product, HttpServletRequest request, MultipartFile file) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		product.setPdate(new Date());
//		上传图片
		if (file != null) {
			String path = request.getServletContext().getRealPath("/products");
			String uploadFileName = file.getOriginalFilename();
			String fileName = UUIDUtiils.getUUID() + uploadFileName;
			File diskFile = new File(path + "//" + fileName);
			file.transferTo(diskFile);
			product.setImage("products/" + fileName);
		}
		System.out.println(product.getImage());
		productService.adminProduct_save(product);
		return "redirect:/admin/adminProduct_findAllByPage.action?page=1";
	}

	@RequestMapping("admin/adminProduct_deletecs")
	public String adminProduct_deletecs(@RequestParam int pid, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		productService.adminProduct_deletecs(pid);
		return "redirect:/admin/adminProduct_findAllByPage.action?page=1";
	}

	/**
	 * 编辑商品
	 * 
	 * @param pid
	 * @param model
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("admin/adminProduct_edit")
	public String adminProduct_edit(@RequestParam int pid, Model model, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		Product product = productService.finbProductByPid(pid);
		model.addAttribute("findByPid", product);
		// 查询出所有的二级分类
		List<Categorysecond> cslist = categorySecondService.findAll();
		model.addAttribute("cslist", cslist);
		return "admin/product/edit";
	}

	@RequestMapping("admin/adminProduct_look")
	public String adminProduct_look(@RequestParam int pid, Model model, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		Product product = productService.finbProductByPid(pid);
		model.addAttribute("findByPid", product);
		// 查询出所有的二级分类
		List<Categorysecond> cslist = categorySecondService.findAll();
		model.addAttribute("cslist", cslist);
		return "admin/product/look";
	}

	@RequestMapping("/adminsearchProduct")
	public String searchProduct(@RequestParam String condition, Model model, HttpServletRequest request)
			throws Exception {
		// 查询一级分类
		List<Category> cList = categoryService.findCategory();
		request.getSession().getServletContext().setAttribute("cList", cList);
		// 查询商品
		List<Product> hList = productService.findHotProduct();
		model.addAttribute("hList", hList);
		// 查询二级商品种类
		List<Categorysecond> categoryList = categorySecondService.findAll();
		model.addAttribute("categoryList", categoryList);
		// 搜索商品
		List<Product> srList = productService.searchProduct(condition);
		model.addAttribute("srList", srList);
		return "admin/product/search";
	}

	@RequestMapping("/admin/adminProduct_update")
	public String adminProduct_update(Product product, HttpServletRequest request, MultipartFile file)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		product.setPdate(new Date());
//		上传图片
		if (file != null) {
			String path = request.getServletContext().getRealPath("/products");
			String uploadFileName = file.getOriginalFilename();
			String fileName = UUIDUtiils.getUUID() + uploadFileName;
			File diskFile = new File(path + "//" + fileName);
			file.transferTo(diskFile);
			product.setImage("products/" + fileName);
		} else {
			product.setImage(null);
		}
		productService.adminProduct_update(product);
		return "redirect:/admin/adminProduct_findAllByPage.action?page=1";
	}

	/** 订单管理模块 **/
	@RequestMapping("/admin/adminOrder_findAllByPage")
	public String adminOrder_findAllByPage(@RequestParam int page, Model model, HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		PageBean<Orders> allProPageBean = orderService.findAllOrderByStateAndPage(page);
		model.addAttribute("pageBean", allProPageBean);
		return "admin/order/list";
	}

	// adminOrder_findByState
	@RequestMapping("/admin/adminOrder_findByState")
	public String adminOrder_findByState(@RequestParam int page, @RequestParam int state, Model model,
			HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		PageBean<Orders> allProPageBean = orderService.findAllOrderByStateAndPage(state, page);
		model.addAttribute("pageBean", allProPageBean);
		return "admin/order/list";
	}

	@RequestMapping("/admin/selectorderByPrimaryKey")
	public String selectorderByPrimaryKey(int oid, Model model, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		List<Orders> orders = orderService.selectorderByPrimaryKey(oid);
		request.setAttribute("orders", orders);
		return "admin/order/selectbyoid";
	}

	// 订单详情
	// adminOrder_findOrderItem
	@RequestMapping("/admin/adminOrder_findOrderItem")
	public String adminOrder_findOrderItem(@RequestParam int oid, Model model, HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}

		Orders orderItems = orderService.findOrderByOid(oid);
		model.addAttribute("orderItems", orderItems);
		return "admin/order/list";
	}

	// 更新订单状态
	@RequestMapping("/admin/adminOrder_updateState")
	public String adminOrder_updateState(@RequestParam int oid, @RequestParam int status, Model model,
			HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		orderService.updateOrderStatus(oid, status);
		return "redirect:/admin/adminOrder_findAllByPage.action?page=1";
	}

	// 后台留言管理
	@RequestMapping("/admin/adminMessage_findAllByPage")
	public String adminMessage_findAllByPage(@RequestParam int page, Model model, HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		PageBean<Message> pageBean = messageService.findAllMessageByPage(page);
		model.addAttribute("pageBean", pageBean);
		return "admin/message/list";
	}

	@RequestMapping("admin/adminMessage_edit")
	public String adminMessage_edit(@RequestParam int messageid, Model model, HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		Message message = messageService.findBymessageid(messageid);
		model.addAttribute("message", message);
		return "admin/message/reply";
	}

	@RequestMapping("admin/adminMessage_update")
	public String adminMessage_update(Message message, HttpServletRequest request) {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		System.out.println("-------------" + message.getReply() + message.getMessageid());
		messageService.adminMessage_update(message);
		/* return "admin/message/list"; */
		return "redirect:/admin/adminMessage_findAllByPage.action?page=1";
	}

	@RequestMapping("/admin/adminMessage_delete")
	public String adminOrder_updateState(@RequestParam int messageid, Model model, HttpServletRequest request)
			throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		messageService.deleteMessage(messageid);
		return "redirect:/admin/adminMessage_findAllByPage.action?page=1";
	}

	// 批量删除
	@RequestMapping("/admin/deleteMessage")
	@ResponseBody
	public String deleteMessage(String deleteList) throws Exception {
		// 因为传递的deleteList为带","的字符串,所以需要消掉分隔符转为数组
		String[] ids = deleteList.split(",");
		for (String id : ids) {
			messageService.deleteMessage(Integer.parseInt(id));
		}
		return "1";
		// return "admin/message/list";
	}

	@RequestMapping("/admin/admin_findAdmin")
	public String admin_findAdmin(Model model, HttpServletRequest request) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		return "admin/user/adminList";
	}

	@RequestMapping(value = "/admin/admin_updatepsw", produces = {
			"application/json;charset=UTF-8" }, method = RequestMethod.GET)
	@ResponseBody
	public ResponseMessage admin_updatepsw(Model model, HttpServletRequest request, @RequestParam String newpsw,
			@RequestParam String againpsw, @RequestParam String password) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (!password.equals(adminuserLogin.getPassword())) {
			return ResponseMessage.error().addObject("sss", "原有密码不正确!");
		}
		if (!newpsw.equals(againpsw)) {
			return ResponseMessage.error().addObject("sss", "两次密码不一致!");

		}
		adminuserLogin.setPassword(newpsw);
		userService.updateAdminPsw(adminuserLogin);
		return ResponseMessage.success().addObject("sss", "修改密码成功，请重新登录!");

	}

	// 查看商品订单详情
	@RequestMapping("/admin/orderDetails")
	public String orderDetails(Model model, HttpServletRequest request, @RequestParam int oid) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		List<Orders> orders = orderService.selectorderByPrimaryKey(oid);
		Orders order = orders.get(0);

		Date currentTime = order.getOrderTime();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strTime = formatter.format(currentTime);

		request.getSession().setAttribute("strTime", strTime);
		System.out.println(orders.toString());
		request.getSession().setAttribute("orders", order);
		return "admin/order/orderDetails";
	}

	// 修改商品状态
	@RequestMapping("/admin/adminProduct_xiajia")
	public String xiajia(Model model, HttpServletRequest request, @RequestParam int pid) throws Exception {
		Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
		if (adminuserLogin == null) {
			request.getSession().setAttribute("message", "对不起您还没有登录");
			return "admin/index";
		}
		Product product = productService.finbProductByPid(pid);
		if (product.getState() == 1) {
			product.setState(0);
		} else {
			product.setState(1);
		}
		productService.adminProduct_updateState(product);
		return "redirect:/admin/adminProduct_findAllByPage.action?page=1";
	}
}
